package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.bairong.BairongPortraitScorelcashonData;
import com.ucredit.babel.common.model.third.bairong.BairongPortraitScorelcashonRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 百融-履约风险识别
 *
 * @author xj
 */

public class BairongPortraitScorelcashonRecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 百融-履约风险识别
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BairongPortraitScorelcashonRecord obj = (BairongPortraitScorelcashonRecord) model;
        BairongPortraitScorelcashonData data = obj.getData();
        if (data == null) {
            return false;
        }

        StringBuilder sb = getBaseInfo(obj, successful);

        // 请求响应状态码
        sb.append(data.getCode() == null ? "" : data.getCode()).append(CRT001);
        // 请求返回单条的操作流水号
        sb.append(data.getSwiftNumber() == null ? "" : data.getSwiftNumber()).append(CRT001);
        // 输出标识
        sb.append(data.getFlag() == null || data.getFlag().getScore() == null ? "" : data.getFlag().getScore()).append(CRT001);
        // 履约风险识别-线上现金分期分
        sb.append(data.getScore() == null || data.getScore().getScorelcashon() == null ? "" : data.getScore().getScorelcashon()).append(CRT001);

        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_bairong_portrait_scorelcashon_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIRONG_PORTRAIT_SCORELCASHON_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百融-履约风险识别";
    }
}
